package com.trz.cqrs.es.event;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import com.trz.cqrs.es.event.priority.EventPriority;
import com.trz.cqrs.es.event.priority.Priority;
import com.trz.cqrs.es.event.priority.Strategy;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.context.ApplicationEvent;

import java.util.UUID;


@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@JsonIgnoreProperties({"$jacocoData", "serialVersionUID", "source", "timestamp"})
@EventPriority(value = Priority.P5, strategy = Strategy.GRADIENT_DESCENT)
public abstract class Event extends ApplicationEvent {

    /**
     * 事件标识
     */
    private Long id;

    /**
     * 是否重试
     */
    private boolean retry;

    /**
     * 执行次数
     */
    private int count;

    /**
     * 业务类别
     */
    @JsonIgnore
    private String category;

    /**
     * 业务标识
     */
    @JsonIgnore
    private String identifier;

    /**
     * 事件类型
     */
    private final String eventType = getClass().getName();

    protected Event() {
        super(UUID.randomUUID());
    }

}
